import { FMVCS } from "../../fgui/fmvc/FMVCS";
import { GlobalEvent } from "../global/Global";
import EventSystem from "../../core/EventSystem";
import SoundCtrl from "../sound/SoundCtrl";
import GameMainCtrl from "../gamemain/GameMainCtrl";

export default class GamePauseView extends FMVCS.FView {
    private _isSound: boolean = true;
    clickHandlers(){
        return [
            [this._views[`btnGoOn`], this.onBtnGoOnClick, this],
            [this._views[`btnRestart`], this.onBtnRestartClick, this],
            [this._views[`btnBackToChoose`], this.onBtnBackToChoose, this],
            [this._views[`btnSound`], this.onBtnSoundClick, this],
        ];
    }

    onOpenCallBack(){
        this._isSound = SoundCtrl.isOn;
        this.setBtnSettingState(this._isSound);
    }

    onBtnGoOnClick(){
        EventSystem.emit(GlobalEvent.UIListenID.UI_BtnGoOn_Click);
    }

    onBtnRestartClick(){
        EventSystem.emit(GlobalEvent.UIListenID.UI_BtnRestart_Click);
    }

    onBtnBackToChoose(){
        EventSystem.emit(GlobalEvent.UIListenID.UI_GameMainView_Close);
        if(GameMainCtrl.data.getIsNormal()){
            EventSystem.emit(GlobalEvent.UIListenID.UI_LevelChooseView_Open);
        }
        else{
            EventSystem.emit(GlobalEvent.UIListenID.UI_MapLocalView_Open);
        }

        this.onClose();
    }

    onBtnSoundClick(){
        this._isSound = !this._isSound;
        this.setBtnSettingState(this._isSound);
        EventSystem.emit(GlobalEvent.UIListenID.UI_SoundSetting, this._isSound);
    }

    setBtnSettingState(state: boolean){
        let btnSound = this._views[`btnSound`].asButton;
        btnSound.getController(`button`).selectedIndex = state ? 1 : 0;
    }
}